package todolist.test;

import todolist.activities.RegisterActivity;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import android.widget.EditText;
import android.widget.TextView;

public class JUnitRegisterActivity extends ActivityInstrumentationTestCase2<RegisterActivity> {
	private RegisterActivity mActivity;  // the activity under test
	private EditText email, username, pw;

	public JUnitRegisterActivity() {
		super("todolist.activities", RegisterActivity.class);
	}
	
	@Override
	protected void setUp() throws Exception {
		super.setUp();
		mActivity = this.getActivity();
		username = (EditText) mActivity.findViewById(todolist.activities.R.id.reg_username);
		pw = (EditText) mActivity.findViewById(todolist.activities.R.id.reg_password);
		email = (EditText) mActivity.findViewById(todolist.activities.R.id.reg_email);
		
	}
	
	public void testARegPreconditions() {
		assertTrue("Things are not null", mActivity.checkForNull(username, email, pw));
	}
	
	/*
	 *These tests achieve branch coverage by entering null data in each of the fields
	 *Each test leaves a field blank, finally one field fills out all data
	 *This is the only test that should succed when asserting false because nothing was null 
	 */
	public void testBUsername() {
		sendKeys("T E S T");
		sendKeys("ENTER");
		assertTrue(mActivity.checkForNull(username, email, pw));
	}
	
	public void testCEmail() {
		sendKeys("ENTER");
		sendKeys("T E S T");
		sendKeys("ENTER");
		assertTrue(mActivity.checkForNull(username, email, pw));
	}
	
	public void testDPW() {
		sendKeys("ENTER");
		sendKeys("ENTER");
		sendKeys("T E S T");
		sendKeys("ENTER");
		assertTrue(mActivity.checkForNull(username, email, pw));
	}
	
    public void testFilledOut() {
		sendKeys("T E S T");
		sendKeys("ENTER");
		sendKeys("T E S T");
		sendKeys("ENTER");
		sendKeys("T E S T");
		sendKeys("ENTER");
		assertFalse(mActivity.checkForNull(username, pw, email));
    }

}
